package org.zasadnyy.redlions.players.client.ui;

import org.zasadnyy.redlions.players.client.ds.PlayerRecord;
import org.zasadnyy.redlions.players.client.ds.PlayersDataSource;

import com.smartgwt.client.widgets.layout.Layout;
import com.smartgwt.client.widgets.tile.events.RecordClickEvent;
import com.smartgwt.client.widgets.tile.events.RecordClickHandler;

public class PlayerCanvas extends Layout {

	public static final int APP_WIDTH = 500;
	public static final int APP_HEIGHT = 300;

	private PlayersDataSource datasource;

	public PlayerCanvas() {
		super();
		datasource = new PlayersDataSource();
		initLayout();
	}

	private void initLayout() {
		setAnimateMembers(true);

		final PlayerInfoLayout infoLayout = new PlayerInfoLayout(datasource);
		infoLayout.hide();

		final PlayersTileGrid tileGrid = new PlayersTileGrid();
		tileGrid.setDataSource(datasource);
		tileGrid.addRecordClickHandler(new RecordClickHandler() {

			@Override
			public void onRecordClick(RecordClickEvent event) {
				infoLayout.setPlayer((PlayerRecord) event.getRecord());
				infoLayout.show();
			}

		});
		addChild(tileGrid);
		tileGrid.fetchData();
		addChild(infoLayout);

//		final EditPlayersLayout editPlayers = new EditPlayersLayout();
//		editPlayers.hide();
//		addChild(editPlayers);
//
//		EditToolsStack toolStack = new EditToolsStack();
//		toolStack.addListClickHandler(new ClickHandler() {
//
//			@Override
//			public void onClick(ClickEvent event) {
//				editPlayers.hide();
//			}
//		});
//		toolStack.addEditClickHandler(new ClickHandler() {
//
//			@Override
//			public void onClick(ClickEvent event) {
//				editPlayers.show();
//			}
//		});
//		addChild(toolStack);
	}

}
